﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NCql.Parser;

namespace NCql.Tests
{
    [TestClass]
    public class CqlQueryParserTest
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        public void ParseTest1()
        {
            var target = new CqlQueryParser();
            string queryString = "dc.title any fish";
            var expectedQuery = new CqlQuery();
            var expectedSearchClause = new SearchClause();
            expectedSearchClause.Relation = new Relation();
            expectedSearchClause.Relation.FullName = "any";
            expectedSearchClause.Index = new Index();
            expectedSearchClause.Index.FullName = "dc.title";

            expectedSearchClause.Term = "fish";

            expectedQuery.Clause = expectedSearchClause;

            CqlQuery actual = target.Parse(queryString);
            Assert.AreEqual(expectedQuery, actual);
        }

        [TestMethod]
        public void ParseTest2()
        {
            var target = new CqlQueryParser();
            string queryString = "dc.title any fish or dc.creator any sanderson";
            var expectedQuery = new CqlQuery();
            var expectedBooleanClause = new BooleanClause();
            expectedQuery.Clause = expectedBooleanClause;
            expectedBooleanClause.BooleanOperator = BooleanOperator.Or;

            var expectedLeftSearchClause = new SearchClause();
            expectedLeftSearchClause.Relation = new Relation();
            expectedLeftSearchClause.Relation.FullName = "any";
            expectedLeftSearchClause.Index = new Index();
            expectedLeftSearchClause.Index.FullName = "dc.title";
            expectedLeftSearchClause.Term = "fish";
            expectedBooleanClause.LeftOperand = expectedLeftSearchClause;

            var expectedRightSearchClause = new SearchClause();
            expectedRightSearchClause.Relation = new Relation();
            expectedRightSearchClause.Relation.FullName = "any";
            expectedRightSearchClause.Index = new Index();
            expectedRightSearchClause.Index.FullName = "dc.creator";
            expectedRightSearchClause.Term = "sanderson";
            expectedBooleanClause.RightOperand = expectedRightSearchClause;

            CqlQuery actual = target.Parse(queryString);
            Assert.AreEqual(expectedQuery, actual);
        }

        [TestMethod]
        public void ParseTest3()
        {
            var target = new CqlQueryParser();
            string queryString = "dc.title any fish sortBy dc.date/sort.ascending";


            CqlQuery actual = target.Parse(queryString);
            Assert.AreEqual(actual.SortSpecs.Length, 1);
            Assert.AreEqual(actual.SortSpecs[0].Order, SortOrder.Ascending);
            Assert.AreEqual(actual.SortSpecs[0].Index.FullName, "dc.date");
        }

        [TestMethod]
        public void ParseTest4()
        {
            var target = new CqlQueryParser();
            string queryString = "\"dinosaur\" sortBy dc.date/sort.descending dc.title/sort.ascending";

            CqlQuery actual = target.Parse(queryString);
            Assert.AreEqual(actual.SortSpecs.Length, 2);
            Assert.AreEqual(actual.SortSpecs[0].Order, SortOrder.Descending);
            Assert.AreEqual(actual.SortSpecs[0].Index.FullName, "dc.date");
            Assert.AreEqual(actual.SortSpecs[1].Order, SortOrder.Ascending);
            Assert.AreEqual(actual.SortSpecs[1].Index.FullName, "dc.title");
            Assert.AreEqual(((SearchClause) actual.Clause).Term, "dinosaur");
        }

        [TestMethod]
        public void ParseTest5()
        {
            var target = new CqlQueryParser();
            string queryString = @"> dc = ""info:srw/context-sets/1/dc-v1.1"" dc.title any fish";
            CqlQuery actual = target.Parse(queryString);
            Assert.AreEqual(1, actual.PrefixAssignments.Length);
            Assert.AreEqual("dc", actual.PrefixAssignments[0].Prefix);
            Assert.AreEqual("info:srw/context-sets/1/dc-v1.1", actual.PrefixAssignments[0].Uri);
        }

        [TestMethod]
        public void ParseTest6()
        {
            var target = new CqlQueryParser();
            string queryString = @"cat";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "cat");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest7()
        {
            var target = new CqlQueryParser();

            CqlQuery q1 = target.Parse(@"""cat""");
            CqlQuery q2 = target.Parse(@"cat");


            Assert.AreEqual(q1, q2);
        }


        [TestMethod]
        public void ParseTest8()
        {
            var target = new CqlQueryParser();
            string queryString = @"comp.os.linux";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "comp.os.linux");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest9()
        {
            var target = new CqlQueryParser();
            string queryString = @"xml:element";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "xml:element");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest10()
        {
            var target = new CqlQueryParser();
            string queryString = @"""prox/word/>=/5""";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "prox/word/>=/5");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest11()
        {
            var target = new CqlQueryParser();
            string queryString = @"(""cat"")";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "cat");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest12()
        {
            var target = new CqlQueryParser();
            string queryString = @"((dog))";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "SERVERCHOICE");
            Assert.AreEqual(searchClause.Relation.FullName, "EQUAL");
            Assert.AreEqual(searchClause.Term, "dog");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest13()
        {
            var target = new CqlQueryParser();
            string queryString = @"title = ""fish""";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, "=");
            Assert.AreEqual(searchClause.Term, "fish");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest14()
        {
            var target = new CqlQueryParser();
            string queryString = @"title exact fish";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, "exact");
            Assert.AreEqual(searchClause.Term, "fish");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest15()
        {
            var target = new CqlQueryParser();
            string queryString = @"title exact fish";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, "exact");
            Assert.AreEqual(searchClause.Term, "fish");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest16()
        {
            var target = new CqlQueryParser();
            string queryString = @"title all fish";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, "all");
            Assert.AreEqual(searchClause.Term, "fish");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest17()
        {
            var target = new CqlQueryParser();
            string queryString = @"title > 9";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, ">");
            Assert.AreEqual(searchClause.Term, "9");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest18()
        {
            var target = new CqlQueryParser();
            string queryString = @"title >= 23";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, ">=");
            Assert.AreEqual(searchClause.Term, "23");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest19()
        {
            var target = new CqlQueryParser();
            string queryString = @"dc.title any ""fish chips""";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "dc.title");
            Assert.AreEqual(searchClause.Relation.FullName, "any");
            Assert.AreEqual(searchClause.Term, "fish chips");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest20()
        {
            var target = new CqlQueryParser();
            string queryString = @"dc.title any/stem fish";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "dc.title");
            Assert.AreEqual(searchClause.Relation.FullName, "any");
            Assert.IsNotNull(searchClause.Relation.Modifiers["stem"]);
            Assert.AreEqual(searchClause.Term, "fish");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest21()
        {
            var target = new CqlQueryParser();
            string queryString = @"dc.fish all/stem/fuzzy ""fish chips""";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "dc.fish");
            Assert.AreEqual(searchClause.Relation.FullName, "all");
            Assert.IsNotNull(searchClause.Relation.Modifiers["stem"]);
            Assert.IsNotNull(searchClause.Relation.Modifiers["fuzzy"]);
            Assert.AreEqual(searchClause.Relation.Modifiers.Count, 2);
            Assert.AreEqual(searchClause.Term, "fish chips");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }

        [TestMethod]
        public void ParseTest22()
        {
            var target = new CqlQueryParser();
            string queryString = @"title any frog";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "title");
            Assert.AreEqual(searchClause.Relation.FullName, "any");
            Assert.AreEqual(searchClause.Relation.Modifiers.Count, 0);
            Assert.AreEqual(searchClause.Term, "frog");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest23()
        {
            var target = new CqlQueryParser();
            string queryString = @"((dc.title any/stem ""frog pond""))";
            CqlQuery actual = target.Parse(queryString);
            var searchClause = (SearchClause) actual.Clause;
            Assert.AreEqual(searchClause.Index.FullName, "dc.title");
            Assert.AreEqual(searchClause.Relation.FullName, "any");
            Assert.AreEqual(searchClause.Relation.Modifiers.Count, 1);
            Assert.IsNotNull(searchClause.Relation.Modifiers["stem"]);
            Assert.AreEqual(searchClause.Term, "frog pond");
            Assert.AreEqual(0, actual.PrefixAssignments.Length);
            Assert.AreEqual(0, actual.SortSpecs.Length);
        }


        [TestMethod]
        public void ParseTest24()
        {
            var target = new CqlQueryParser();
            string queryString = @"cat or dog";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Or, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("cat", leftClause.Term);
            Assert.AreEqual("dog", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest25()
        {
            var target = new CqlQueryParser();
            string queryString = @"cat and fish";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.And, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("cat", leftClause.Term);
            Assert.AreEqual("fish", rightClause.Term);
        }

        [TestMethod]
        public void ParseTest26()
        {
            var target = new CqlQueryParser();
            string queryString = @"cat not frog";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Not, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("cat", leftClause.Term);
            Assert.AreEqual("frog", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest27()
        {
            var target = new CqlQueryParser();
            string queryString = @"(cat not frog)";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Not, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("cat", leftClause.Term);
            Assert.AreEqual("frog", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest28()
        {
            var target = new CqlQueryParser();
            string queryString = @"""cat"" not ""fish food""";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Not, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("cat", leftClause.Term);
            Assert.AreEqual("fish food", rightClause.Term);
        }

        [TestMethod]
        public void ParseTest29()
        {
            var target = new CqlQueryParser();
            string queryString = @"xml and ""prox/word/""";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.And, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("xml", leftClause.Term);
            Assert.AreEqual("prox/word/", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest30()
        {
            var target = new CqlQueryParser();
            string queryString = @"fred and any";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.And, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("fred", leftClause.Term);
            Assert.AreEqual("any", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest31()
        {
            var target = new CqlQueryParser();
            string queryString = @"((fred or all))";
            CqlQuery actual = target.Parse(queryString);
            var booleanClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Or, booleanClause.BooleanOperator);

            var leftClause = (SearchClause) booleanClause.LeftOperand;
            var rightClause = (SearchClause) booleanClause.RightOperand;

            Assert.AreEqual("SERVERCHOICE", leftClause.Index.FullName);
            Assert.AreEqual("SERVERCHOICE", rightClause.Index.FullName);

            Assert.AreEqual("EQUAL", leftClause.Relation.FullName);
            Assert.AreEqual("EQUAL", rightClause.Relation.FullName);

            Assert.AreEqual("fred", leftClause.Term);
            Assert.AreEqual("all", rightClause.Term);
        }


        [TestMethod]
        public void ParseTest32()
        {
            var target = new CqlQueryParser();
            string queryString = @"a or b and c not d";
            CqlQuery actual = target.Parse(queryString);
            var abcdClause = (BooleanClause) actual.Clause;

            Assert.AreEqual(BooleanOperator.Not, abcdClause.BooleanOperator);
            var dClause = (SearchClause) abcdClause.RightOperand;
            Assert.AreEqual("d", dClause.Term);
            Assert.AreEqual("EQUAL", dClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", dClause.Index.FullName);

            var abcClause = (BooleanClause) abcdClause.LeftOperand;
            Assert.AreEqual(BooleanOperator.And, abcClause.BooleanOperator);
            var cClause = (SearchClause) abcClause.RightOperand;
            Assert.AreEqual("c", cClause.Term);
            Assert.AreEqual("EQUAL", cClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", cClause.Index.FullName);

            var abClause = (BooleanClause) abcClause.LeftOperand;
            Assert.AreEqual(BooleanOperator.Or, abClause.BooleanOperator);
            var bClause = (SearchClause) abClause.RightOperand;
            Assert.AreEqual("b", bClause.Term);
            Assert.AreEqual("EQUAL", bClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", bClause.Index.FullName);

            var aClause = (SearchClause) abClause.LeftOperand;

            Assert.AreEqual("a", aClause.Term);
            Assert.AreEqual("EQUAL", aClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", aClause.Index.FullName);
        }

        [TestMethod]
        public void ParseTest33()
        {
            var target = new CqlQueryParser();
            string queryString = @"a Or b AnD c NOT d";
            CqlQuery actual = target.Parse(queryString);
            var abcdClause = (BooleanClause)actual.Clause;

            Assert.AreEqual(BooleanOperator.Not, abcdClause.BooleanOperator);
            var dClause = (SearchClause)abcdClause.RightOperand;
            Assert.AreEqual("d", dClause.Term);
            Assert.AreEqual("EQUAL", dClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", dClause.Index.FullName);

            var abcClause = (BooleanClause)abcdClause.LeftOperand;
            Assert.AreEqual(BooleanOperator.And, abcClause.BooleanOperator);
            var cClause = (SearchClause)abcClause.RightOperand;
            Assert.AreEqual("c", cClause.Term);
            Assert.AreEqual("EQUAL", cClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", cClause.Index.FullName);

            var abClause = (BooleanClause)abcClause.LeftOperand;
            Assert.AreEqual(BooleanOperator.Or, abClause.BooleanOperator);
            var bClause = (SearchClause)abClause.RightOperand;
            Assert.AreEqual("b", bClause.Term);
            Assert.AreEqual("EQUAL", bClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", bClause.Index.FullName);

            var aClause = (SearchClause)abClause.LeftOperand;

            Assert.AreEqual("a", aClause.Term);
            Assert.AreEqual("EQUAL", aClause.Relation.FullName);
            Assert.AreEqual("SERVERCHOICE", aClause.Index.FullName);
        }
    }
}